<?php

namespace app\common\model;

use think\Model;
use traits\model\SoftDelete;

class ShopApply extends Model
{

    use SoftDelete;

    

    // 表名
    protected $name = 'shop_apply';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
//        'status_text'
    ];
    

    
    public function getStatusList()
    {
        return ['2' => __('Status 2'), '3' => __('Status 3')];
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }
    public function getLogoAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['logo']) ? $data['logo'] : '');
        return get_app_image_url($value);
    }
    public function getAvatarAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['avatar']) ? $data['avatar'] : '');
        return get_app_image_url($value);
    }
    public function cateid(){
        return $this->belongsTo('GoodsCategory', 'cate_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public static function getShop($shop_id,$status=2,$type=2){
        $where['shop_apply.id']=$shop_id;
        $where['shop_apply.status']=$status;
        $where['shop_apply.type']=$type;
        $info = self::where($where)
            ->with(['cateid'])
            ->find();
        return $info;
    }
    /**
     * 获取店铺商品数量
     * */
    public static function goodsNum($where=[]){
        $where['status'] = '1';
        $where['state']  = '1';
        $goods = Goods::where($where)->count();
        $goods1=Goods1::where($where)->count();
        return $goods+$goods1;
    }
}
